package com.qdu.mapper;

import com.qdu.bean.bikeWritable;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class WeekDaAvgMapper extends Mapper<LongWritable, Text, Text, IntWritable> {



    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] data = line.split(",");
        String[] datee = data[0].split(" ");

        //将日期转化为星期，retur weekDays[w]
        SimpleDateFormat ft=new SimpleDateFormat("yyyy/MM/dd");
        try {
            Date date =ft.parse(datee[0]);
            String[] weekDays = {"7","1","2","3","4","5","6"};
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            int w = cal.get(Calendar.DAY_OF_WEEK) -1<0?0:cal.get(Calendar.DAY_OF_WEEK) -1;
            //人数
            int count = Integer.parseInt(data[11]);
            context.write(new Text(weekDays[w]) ,new IntWritable(count));

        } catch (ParseException e) {
            e.printStackTrace();
        }

        //人数
        //int count = Integer.parseInt(data[11]);



        //context.write(new Text(weekDays[w]) ,new IntWritable(count));

    }
}
